package cc.messcat.dao.map;

import cc.messcat.common.dao.BaseDaoImpl;
import cc.messcat.entity.map.MapPoint;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 扶贫地图持久层实现
 *
 * @author Administrator
 * @create 2018-06-10 15:17
 **/
@Repository
public class PovertyMapDaoImpl extends BaseDaoImpl<MapPoint> implements PovertyMapDao {
    /**
     * 根据ID查询企业类型标注点信息
     *
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> queryCompanyMapPointInfo(Long id) {
        StringBuffer sql = new StringBuffer("select * from company t where t.id=?");
        List<Map<String, Object>> toMapBySql = findToMapBySql(sql.toString(), id);
        return toMapBySql.size() > 0 ? toMapBySql.get(0) : null;
    }

    /**
     * 根据ID查询村子类型标注点信息
     *
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> queryVillageMapPointInfo(Long id) {
        return null;
    }

    /**
     * 更新标注点信息
     *
     * @param mapPoint
     */
    @Override
    public void modifyMapPointBysql(MapPoint mapPoint) {
        String sql = "update MapPoint mp set mp.infoId = " + mapPoint.getInfoId() + " where mp.id=" + mapPoint.getId();
        modifyByHql(sql);
    }

    /**
     * 根据标注类型查询标注点信息
     *
     * @param pointTypes
     * @return
     */
    @Override
    public List<MapPoint> queryMapPointsBypPointTypes(String[] pointTypes) {
        List<MapPoint> mapPoints = new ArrayList<MapPoint>();
        for (int i = 0; i < pointTypes.length; i++) {
            String hql = "from MapPoint mp where mp.pointType='" + pointTypes[i] + "'";
            mapPoints.addAll(find(hql));
        }
        return mapPoints;
    }
}
